package com.doudou.oauth.validate;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * @Author: 傻男人
 * @Date: 2020/5/21 15:27
 * @Version: 1.0
 * @Description: 验证码
 */
@Data
public class ValidateCode implements Serializable {

    @ApiModelProperty("验证码")
    private String validateCode;

    @ApiModelProperty("过期时间")
    private LocalDateTime expireTime;

    public ValidateCode(String validateCode, int expireSecond) {
        this.validateCode = validateCode;
        this.expireTime = LocalDateTime.now().plusSeconds(expireSecond);
    }

    public ValidateCode(String code, LocalDateTime expireTime){
        this.validateCode = code;
        this.expireTime = expireTime;
    }

    /**
     * 如果过期时间在当前日期之前，则验证码过期
     * @return
     */
    public boolean hasExpired(){
        return LocalDateTime.now().isAfter(expireTime);
    }
}
